package yu.liu.personal.app.myapplication.utils;

import android.content.Context;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import yu.liu.personal.app.myapplication.R;

/**
 * Created by Administrator on 2016/9/24.
 */

public class ResourceManager {

    private WeakReference<Context> refContext;
    //    private Context resContext;
    private static ResourceManager manager = null;

    private HashMap<String, Integer> avgTypeMap;

    private ResourceManager(Context context) {
        refContext = new WeakReference<>(context);
//        resContext = context;
        avgTypeMap = new HashMap<>();
        avgTypeMap.put("强攻", R.drawable.icon_avg_type_1);
        avgTypeMap.put("重击", R.drawable.icon_avg_type_2);
        avgTypeMap.put("支援", R.drawable.icon_avg_type_3);
        avgTypeMap.put("突袭", R.drawable.icon_avg_type_4);
        avgTypeMap.put("格斗", R.drawable.icon_avg_type_5);
        avgTypeMap.put("爆轰", R.drawable.icon_avg_type_6);
        avgTypeMap.put("狙击", R.drawable.icon_avg_type_7);
    }

    private static synchronized void syncInit(Context context) {
        if (manager == null) {
            manager = new ResourceManager(context);
        }
    }

    public static ResourceManager getManager(Context context) {
        if (manager == null) {
            syncInit(context.getApplicationContext());
        }
        return manager;
    }

    public int getResourceID(String resType, String resName) {
        return refContext.get().getResources()
                .getIdentifier(resName, resType, refContext.get().getPackageName());
    }

    public int getAVGType(String type) {
        Integer id = avgTypeMap.get(type);
        if (id == null) {
            id = 0;
        }
        return id;
    }

}
